const mongoose = require('mongoose')
const Schema = mongoose.Schema
const model = mongoose.model.bind(mongoose)
const ObjectId = mongoose.Schema.Types.ObjectId

// 数据表
const productSchema = Schema({
  id: ObjectId,
  name: String,
  description: String,
  image: String,
  price: Number,
  manufacturer: {type: ObjectId, ref: 'Manufacturer'}
})

const manufacturerSchema = Schema({
  // 主键
  id: ObjectId,
  name: String
})

// 数据库模型
const Product = model('Product', productSchema)
const Manufacturer = model('Manufacturer', manufacturerSchema)

module.exports = {Product, Manufacturer}
